﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Diagnostics;

namespace JigsawService.Utility
{
    public class LogUtility
    {
        public LogUtility()
        {

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ex"></param>
        /// <returns></returns>
        public string GetExceptionInfo(Exception ex)
        {
            string errmsg = "\n\nException Info" +
                            "\n--------------------" +
                            "\nError Type: " + ex.GetType().Name.ToString() +
                            "\nError Source: " + ex.Source.ToString() +
                            "\nError Target: " + ex.TargetSite.ToString() +
                            "\nError Message: " + ex.Message.ToString() +
                            "\nError Stack: " + ex.StackTrace.ToString();

            return errmsg;
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="errmsg"></param>
        public void WriteToEventLog(string errmsg)
        {
            System.Diagnostics.EventLog JigsawService = new EventLog();
            if (!System.Diagnostics.EventLog.SourceExists("JigsawService")) System.Diagnostics.EventLog.CreateEventSource("JigsawService", "Application");
            JigsawService.Source = "JigsawService";
            JigsawService.WriteEntry(errmsg);
        }
    }
}